/**
 * layer.js 扩展
 * Created on 2016/9/22 11:26
 */

/**
 * 未登录状态上传文件
 * Created by  on 2016/9/22 16:50
 */
layer.uploadFile=function(title,datas,fn){
    var defoption ={
//			callback:,
//			userpath:,
//			extensions,
        fileNumLimit:1,
        multiple:false
    };
    var newdata=$.extend(defoption,datas);
    //加载层-风格3
    layer.load(2);

    $.ajax({
        url: "/uploader/v_file",
        data:newdata,
        success: function (data) {
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                shadeClose: true,
                content: data,
                success:function(index){
                    layer.closeAll('loading');
                }
            });

            if(fn){
                fn(data);
            }
        }

    });
};

/*默认提示,短暂2秒*/
layer.msgShort=function(content){
    return  layer.msg(content, {time:2000});
};

layer.msgBigShort=function(content){
    return  layer.msg(content, {time:5000});
};

/*不自动关闭的提示*/
layer.msgKeep=function(content){
    return layer.msg(content, {time:0});
};

/*不自动关闭且带蒙版*/
layer.msgLock=function(content){
    return layer.msg(content,{time:0,shade:0.3});
};

layer.post= function(obj,content) {
    content=content||"";
    var index;
    var newparam = $.extend({
        type : "post",
        dataType : "json",
        beforeSend : function() {
            if(content==""){
                index = layer.load(2,{shade:0.1});
            }else{
                index = layer.msgLock(content);
            }
        },
        complete : function() {
            layer.close(index);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msgShort(XMLHttpRequest.status);
        }
    },obj);
    $.ajax(newparam);
};
layer.get= function(obj,content) {
    content=content||"";
    var index;
    var newparam = $.extend({
        type : "get",
        dataType : "json",
        beforeSend : function() {
            if(content==""){
                index = layer.load(2,{shade:0.1});
            }else{
                index = layer.msgLock(content);
            }

        },
        complete : function() {
            layer.close(index);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msgShort(XMLHttpRequest.status);
        }
    },obj);
    $.ajax(newparam);
};




/*选择系统
* url:
* data:{callback:选择回调方法名称,current:默认选中的系统}
* obj:打开吸附的对象this
*
* */
layer.category = function (url,data,obj) {
    layer.post({
        url:"/category/choose",
        dataType:"html",
        data:data,
        success:function (str) {
            layer.tips(str,obj,{tips: [2,"rgb(232, 235, 243)"],time:0,shade:0.001,shadeClose:true,maxWidth:"auto"}); 
        }
    });
};

layer.login=function(callbackName){
    var data = {};
    if(callbackName!=null){
        data.callback =callbackName;
    }
    $.get('/user/loadLoginWin',data,function(data) {
        layer.open({
            type: 1,
            title : '请登录',
            //skin: 'layui-layer-rim', //加上边框
            area: ['370px', '450px'], //宽高
            content: data
        });
    });
};

layer.bindPhone=function (callbackName) {
    var data = {};
    if(callbackName!=null){
        data.callback =callbackName;
    }
    $.get("/user/bindPhone",data,function (result) {
        layer.open({
            type:1,
            title:"绑定手机号",
            area: ['720px', '250px'], //宽高
            content:result
        })
    })
};

/*
*
* 文件管理系统
* */
var fileOptions;
layer.fileManager = function(options){
    var fileDialog;
    fileOptions = $.extend({
        initType : "image" , //初始化上传类型，分image和file两种
        multiple : false , //是否多选，默认false
        callback : function(data){//回调函数
            console.log(data);
        },
        pageNo : 1,//页码
        close : function(){//关闭弹窗
            layer.close(fileDialog);
        },
        cancel : function(){//取消按钮的方法
            layer.close(fileDialog);
        },
        shade : true ,//是否锁屏
        suffixTypes : "" ,//文件类型 (可选) 用英文逗号分隔
        choiseTypes : "",//选件系统可选的文件类型 (可选) 用英文逗号分隔
        fileSingleSizeLimit : 5242880//上传文件大小  默认5M
    }, options || {});
    fileOptions.loading =  function(chioseId){
        var load = layer.load(2);
        $.ajax({
            url : '/user/fileManagerNew' ,
            type : 'post' ,
            dataType : 'html' ,
            data : {initType : fileOptions.initType , multiple : fileOptions.multiple , pageNo : fileOptions.pageNo ,chioseId : chioseId},
            success : function(data){
                layer.close(fileDialog);
                fileDialog = layer.open({
                    title:false,
                    type: 1,
                    content: data,
                    area: ['860px' , '562px'],
                    shade : fileOptions.shade?0.1:false
                    // closeBtn:0
                });
                layer.close(load);
            }
        });
    }
    fileOptions.loading();
    return false;
}


